#ifndef SH_CONSOLE_H
#define SH_CONSOLE_H

#include "gui_color.h"
#include "gui_spirit.h"

typedef struct sh_console
{
    uint32_t width, height;
    uint32_t cursors;
    uint8_t *cur_pos;
    uint32_t text_width, text_height;
    uint32_t rows;
    uint32_t columns;
    uint32_t columns_w;
    uint32_t rows_height;
    gui_color_t background_color;
    gui_color_t font_color;
    uint8_t *buffer;
    uint32_t buffsz;
    void (*outchar)(char ch);
    void (*outstr)(char *str);
    void (*clear)(void);
    void (*clear_area)(int x1, int y1, int x2, int y2);
    void (*flush)(void);
    gui_spirit_t *window;
} sh_console_t;

extern sh_console_t console;

// font info
#define CON_TEXT_WIDTH 8
#define CON_TEXT_HEIGHT 16

// code page numbers
#define CON_FRAME_NR 20

#define CON_BACK_COLOR GUI_BLACK
#define CON_FRONT_COLOR GUI_WHITE

int terminal_console_init();
void terminal_console_putchar(char ch);
int terminal_console_printf(const char *fmt, ...);
void terminal_console_set_frontcolor(gui_color_t color);
void terminal_console_set_backcolor(gui_color_t color);
static void terminal_console_outstr(char *str);
void terminal_console_output_visual(char ch, int x, int y);
void terminal_console_flush2(int mx0, int my0, int mx1, int my1);
void terminal_console_region_chars(int x0, int y0, int x1, int y1);
void scroll_screen();
int can_scroll_up();
int can_scroll_down();
void terminal_console_get_key(int keycode, int kmod);
void terminal_console_select_char(int cx, int cy);
static void terminal_console_clear();
void draw_chars_to_window();
void terminal_console_get_chars(char *buff, int count, int x, int y);
void terminal_console_set_chars(char ch, int count, int x, int y);
void terminal_console_set_char(char ch, int x, int y);
void terminal_console_get_char(char *ch, int x, int y);
int exit_console();
#define terminal_console_exit exit_console

#define console_printf terminal_console_printf
#define console_putchar terminal_console_putchar
#define console_set_chars terminal_console_set_chars
#define console_get_chars terminal_console_get_chars

#define shell_printf console_printf
#define shell_putchar console_putchar
#endif